unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Button1: TButton;
    Button2: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure CirclePoints(x, y : integer);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  x0, y0, r, Xend : integer;

implementation

{$R *.dfm}

procedure TForm1.CirclePoints(x, y: integer);
begin
  Canvas.MoveTo(x0+y, y0+x); Canvas.LineTo(x0+y, y0+x);
  Canvas.MoveTo(x0+y, y0-x); Canvas.LineTo(x0+y, y0-x);
  Canvas.MoveTo(x0+x, y0-y); Canvas.LineTo(x0+x, y0-y);
  Canvas.MoveTo(x0-x, y0-y); Canvas.LineTo(x0-x, y0-y);
  Canvas.MoveTo(x0-y, y0-x); Canvas.LineTo(x0-y, y0-x);
  Canvas.MoveTo(x0-y, y0+x); Canvas.LineTo(x0-y, y0+x);
  Canvas.MoveTo(x0-x, y0+y); Canvas.LineTo(x0-x, y0+y);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  x0 := 200;
  y0 := 200;
  r := 150;
  Xend := trunc(r * Cos(0.785));
  Form1.Label1.Caption:='R/sqrt(2)='+IntToStr(Xend);
  Form1.Label2.Caption:='R='+IntToStr(r);
  Canvas.Pen.Color := clred;
  Canvas.Pen.Width := 2;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  i, x, y : integer;
begin
  Canvas.MoveTo(x0,y0);
  Canvas.LineTo(x0,y0);
  Canvas.MoveTo(x0,y0+r);
  Canvas.LineTo(x0,y0+r);
  for i := 0 to Xend do
  begin
    x := i;
    if sqrt(r*r - i*i)-trunc(sqrt(r*r - i*i))>0.5 then
    begin
      y := trunc(sqrt(r*r - i*i)) + 1;
    end
    else
    begin
      y := trunc(sqrt(r*r - i*i));
    end;
    Canvas.MoveTo(x0+x,y0+y);
    Canvas.LineTo(x0+x,y0+y);
    CirclePoints(x, y);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  x, y : integer;
begin
  x := 0;
  y := r;
  Form1.Canvas.MoveTo(x0,y0+y);
  Form1.Canvas.LineTo(x0,y0+y);
  while x<>y do
  begin
    Inc(x);
    if sqrt(r*r - x*x)-y >= 0.5 then
    begin
      inc(y);
    end;
    Form1.Canvas.MoveTo(x0+x,y0+y);
    Form1.Canvas.LineTo(x0+x,y0+y);
    CirclePoints(x, y);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  x, y : integer;
begin
  r := r-10;
  x := 0;
  y := r;
  Form1.Canvas.MoveTo(x0,y0-y);
  Form1.Canvas.LineTo(x0,y0-y);
  while x<>y do
  begin
    Inc(x);
    if y-sqrt(r*r - x*x) >= 0.5 then
    begin
      y := y-1;
    end;
    Form1.Canvas.MoveTo(x0+x,x0+y);
    Form1.Canvas.LineTo(x0+x,x0+y);
    CirclePoints(x, y);
  end;
end;

end.
